﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace EduSpeed
{
    public partial class FormSetting : Form
    {
        public FormSetting()
        {
            InitializeComponent();
        }

        private void FormSetting_Load(object sender, EventArgs e)
        {
            StreamReader sr = new StreamReader(Path.GetDirectoryName(Application.ExecutablePath) + "\\ProxySwitchConfig.PAC", Encoding.Default);
            textBoxOverride.Text = sr.ReadToEnd();
            sr.Close();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            StreamWriter sw = new StreamWriter(Path.GetDirectoryName(Application.ExecutablePath) + "\\ProxySwitchConfig.PAC", false, Encoding.Default);
            sw.Write(textBoxOverride.Text);
            sw.Close();

            this.Close();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonAbout_Click(object sender, EventArgs e)
        {
            MessageBox.Show("搜狗全网加速控制器 Ver 1.2\r\n\r\nThis program is released under the General Public License.\r\n(C) 2011 Amemiya.");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int i = textBoxOverride.Text.IndexOf("///{%INSECTHERE%}///");
            if (i != -1)
                textBoxOverride.Text = textBoxOverride.Text.Insert(i, Resource.dnsResolve);
            else
                textBoxOverride.SelectedText = Resource.dnsResolve;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int i = textBoxOverride.Text.IndexOf("///{%INSECTHERE%}///");
            if (i != -1)
                textBoxOverride.Text = textBoxOverride.Text.Insert(i, Resource.shExpMatch);
            else
                textBoxOverride.SelectedText = Resource.shExpMatch;
        }
    }
}